package com.sfx.admin.controller;

import com.sfx.admin.common.convention.result.Result;
import com.sfx.admin.common.convention.result.Results;
import com.sfx.admin.dto.req.GroupSortReqDTO;
import com.sfx.admin.dto.req.GroupUpdateReqDTO;
import com.sfx.admin.dto.req.ShortLinkCreateGroupReqDTO;
import com.sfx.admin.dto.resp.GroupRespDTO;
import com.sfx.admin.service.IGroupService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequiredArgsConstructor
public class GroupController {

    private final IGroupService groupService;

    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> saveGroup(@RequestBody ShortLinkCreateGroupReqDTO requestParam) {
        groupService.saveGroup(requestParam);
        return Results.success();
    }

    /**
     * 支持手动拖拽的
     *
     * @return 返回短链接集合
     */
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<GroupRespDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> update(@RequestBody GroupUpdateReqDTO requestParam) {
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> delete(String gid) {
        groupService.deleteGroup(gid);
        return Results.success();
    }

    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> groupSort(@RequestBody List<GroupSortReqDTO> requestParam) {
        groupService.groupSort(requestParam);
        return Results.success();
    }
}